/*
 * 创建日期 2009-12-14
 *
 * 成都天和软件公司
 * 电话：028-85425861
 * 传真：028-85425861-8008
 * 邮编：610041 
 * 版权所有
 */
package  org.fantasy.common.grid.report;

import  org.fantasy.common.db.bean.ReportRow;
import  org.fantasy.common.grid.bean.ReportParam;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *  功能说明
 * @author: 王文成
 * @version: 1.0
 * @since 2009-12-14
 */
public class ReportStatBuilder extends ReportHtmlBuilder {

    private static final Log log = LogFactory.getLog(ReportStatBuilder.class);

    public ReportStatBuilder(ReportParam param) throws Exception {
        super(param);
    }
    
    /**
     * 构建表体
     * 
     * @throws Exception
     */
    @Override
    protected StringBuffer buildBody() throws Exception {
        StringBuffer html = new StringBuffer(1024);
        for (int i = 0; i < resultList.size(); i++) {
            String rowID = "row" + i;
            ReportRow row = resultList.get(i);
            boolean isSum = row.isSubTotal() || row.isSumTotal();
            html.append("<tr id='" + rowID + "' index='" + i + "' " + getRowStyle(row, i));
            // 标注统计行，统计行所统计的列。
            if( isSum ){
                html.append(" sum='" + isSum + "'");
                html.append(" stat='" + row.getStatCol() + "'");
            }
            html.append(">\n");
            html.append(buildCells(row));
            html.append("</tr>\n");
        }
        return html;
    }
}
